{% extends "base.html" %}
{% load i18n plmapp_tags %}

<!-- Manage html display in the Content div which correspond to the "users" menu -->

{% block content %}
    <div id="group_users"/>
        <h3 class="hplm">{% trans "Users" %}</h3>
        <form method="post" action="">{% csrf_token %}	

            {{ user_formset.management_form }}
            {% if is_owner %}
                <a class="tb-btn tb-btn-primary" href="./add/">{% trans "Invite another user" %}</a>
                {% if user_formset.forms %}
                    <input type="submit" class="tb-btn tb-btn-danger" value="{% trans "Remove selected users" %}"/>
                {% endif %}
            {% else %}
                {% if not in_group %}
                    <a class="tb-btn" href="./join/"><span class="ui-button-text">{% trans "Ask to join this group" %}</span></a>
                {% endif %}
            {% endif %}

            <table class="Content">
                <tr>
                    {% if is_owner %}
                        <th class="Content" style="width:50px; text-align:center"></th>
                    {% endif %}
                    <th class="Content" > {% trans "Username" %} </th>
                    <th class="Content" > {% trans "First name" %} </th>
                    <th class="Content" > {% trans "Last name" %} </th>
                </tr>
                <tr class="Content"> 
                    {% if is_owner %}
                        <td class="Content" style="width:50px; text-align:center"></td>
                    {% endif %}

                    <td class="Content"> 
                        <a href="/user/{{obj.owner.username|urlencode }}/">
                            {{ obj.owner.username }}
                        </a>
                    </td>
                    <td class="Content"> {{ obj.owner.first_name }} </td>
                    <td class="Content"> {{ obj.owner.last_name }} </td>
                </tr>

                {% for form in user_formset.forms %}
                    {{ form.id }}
                    {{ form.user }}
                    {{ form.group }}

                    <tr class="Content"> 
                        {% if is_owner %}
                            <td class="Content" style="width:50px; text-align:center">{{ form.delete }}</td>
                        {% endif %}

                        <td class="Content"> 
                            <a href="/user/{{form.user_data.username|urlencode }}/">
                                {{ form.user_data.username }}
                            </a>
                        </td>
                        <td class="Content"> {{ form.user_data.first_name }} </td>
                        <td class="Content"> {{ form.user_data.last_name }} </td>
                    </tr>
                {% endfor %}
            </table>
        </form>

    </div>

    {% if pending_invitations %}
        <div id="pending_invitations">
            <h3 class="hplm">{% trans "Pending invitations" %}</h3>
            <p>{% trans "The following invitations have been sent but guests have not yet accepted them." %}
            {% include "groups/pending_invitations.html" %}
        </div>
    {% endif %}
{% endblock %}


